package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Answer;
import cn.wolfcode.luowowo.article.domain.AnswerComment;
import cn.wolfcode.luowowo.article.mapper.AnswerMapper;
import cn.wolfcode.luowowo.article.query.AnswerQuery;
import cn.wolfcode.luowowo.article.service.IAnswerService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class AnswerServiceImpl implements IAnswerService {
    @Autowired
    private AnswerMapper answerMapper;


    @Override
    public PageInfo query(AnswerQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(),qo.getOrderByRelease());
        return new PageInfo( answerMapper.selectForList(qo));
    }

    @Override
    public int countByQuestionId(Long questionId) {
       return answerMapper.selectCountByQuestionId(questionId);
    }

    @Override
    public void saveOrUpdate(Answer answer) {
        if (answer.getId() ==null){
            answerMapper.insert(answer);
        }else {
            answerMapper.updateByPrimaryKey(answer);
        }
    }

}
